package com.gameObjects;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.util.Log;

import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Input.TouchEvent;
import com.badlogic.androidgames.framework.gl.SpriteBatcher;
import com.baseinfinityrun.Assets;
import com.baseinfinityrun.GameScreen;

public class Child extends Era
{
	ChildPlayer player;
	
	public Child(ChildPlayer p, Background b, Game game)
	{
		super(p, b, game);
		this.player = p;

		try
		{
			stream = game.getFileIO().readAsset("child.xml");
		}
		
		catch(IOException e){}
		
		LoadObstacle(stream);
		actualEraID = 0;
	}

	@Override
	public void Update(float deltaTime) 
	{
		ChangeBg();
		player.Update(deltaTime);
		if(touchEvents != null)
			for(int i = 0; i < touchEvents.size(); i++)
			{
				TouchEvent ev = touchEvents.get(i);
				if(ev.type == TouchEvent.TOUCH_DOWN)
				{
					if(ev.x < GameScreen.screenSize.x / 2)
					{
						this.player.TouchLeft();
					}
					
					if(ev.x > GameScreen.screenSize.x / 2 && this.player.canJump)
					{
						this.player.TouchRight();
					}
				}
			}
	}

	@Override
	public void Draw(SpriteBatcher batcher) 
	{
		lastBg.Draw(batcher);
		actualBg.Draw(batcher);
		player.Draw(batcher);	
		for(Obstacle obs : obstacles)
		{
			obs.Draw(batcher);
		}
	}

	@Override
	public String CollisionObstacles() {
		// TODO Auto-generated method stub
		return null;
	}
}
